#include "MHD.h"
#include "appBll.h"
mr_log_p  request_log,response_log,error_log,MHD_log,bdb_log;
mr_conf_p pconf;
int main (){

	char 	* 	httpdocs;		
	char 	*  	MHD_PORT;
	char *  loglevel;
        char *console ; int consoli ; 
	int logl;

	mr_conf_load(&pconf,"conf.conf");
	mr_conf_get(pconf,"log","console",&console);
	consoli=atoi(console);
	mr_conf_get(pconf,"www","docroot",&httpdocs);
	mr_conf_get(pconf,"www","port",&MHD_PORT);
	mr_conf_get(pconf,"log","loglevel",&loglevel);
	logl =atoi(loglevel);
	
	dbs.data_dir ="db/data";
//	dbs.home ="db/";
	mr_logger_init(&request_log,logl, "switch_request.log",1024000,consoli);
	mr_logger_init(&response_log,logl, "switch_response.log",1024000,consoli);
	mr_logger_init(&error_log,logl, "switch_error.log",1024000,consoli);
	mr_logger_init(&MHD_log,logl, "MHD.log",1024000,consoli);
	mr_logger_init(&bdb_log,logl, "bdb.log",1024000,consoli);

	printf("Listen To PORT '%s'\n",MHD_PORT);

	if(iserver_init(atoi(MHD_PORT)))
	{
		printf("Eroor init MHD \n");
		mr_logger_write(request_log,(LogLevel)loglevel, " Error Init MHD " );
	}


	database_open(DB_CREATE);
// DIRECTORY my_directory;
//	  directory_create( my_directory );
	  /*
	  
	  
	  show_vendor_record("1234", my_switch.directory_dbp);*/

	getchar ();
	iserver_close();
       //	MHD_stop_daemon (aemon);
        database_close();
	mr_logger_destroy(bdb_log);
	mr_logger_destroy(MHD_log);
	mr_logger_destroy(error_log);
	mr_logger_destroy(response_log);
//free(httpdocs); 
	mr_logger_destroy(request_log);
	mr_conf_free(pconf);
	 return 0;
}
